package com.hook3.pianke.Adapter;

import android.app.Activity;
import android.media.Image;
import android.support.v4.view.PagerAdapter;
import android.util.Log;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ImageView;

import com.hook3.pianke.activity.ReadingActivity;

import org.xutils.x;

import java.util.ArrayList;
import java.util.List;

/**
 * Created by Administrator on 2015/12/9.
 */
public class ReadViewPagerAdapter extends PagerAdapter {

    public Activity activity;
    public List<ReadingActivity.MainImageViewPager> imageUrl;

    public ReadViewPagerAdapter(Activity activity,  List<ReadingActivity.MainImageViewPager> imageUrl) {
        this.activity = activity;
        this.imageUrl = imageUrl;
        Log.e("TAG",imageUrl.size()+"");
    }

    @Override
    public int getCount() {
        return imageUrl.size();
    }

    @Override
    public boolean isViewFromObject(View view, Object object) {
        return view==object;
    }

    @Override
    public Object instantiateItem(ViewGroup container, int position) {
        ImageView imageView = new ImageView(activity);
        x.image().bind(imageView,imageUrl.get(position).img);

        container.addView(imageView);

        return imageView;
    }

    @Override
    public void destroyItem(ViewGroup container, int position, Object object) {
        container.removeView((View)object);
    }

}
